// 引入axios
import axios from 'axios'
// import { reject, resolve } from 'core-js/fn/promise'
// import { config } from 'vue/types/umd'
// 创建新的axios
let http = axios.create({
    // baseURL:'https://www.thenewstep.cn/v1/vue3system/api/',
    baseURL: '/api',
    timeout: 3000,
})
// 请求拦截
http.interceptors.request.use(
    //请求成功回调
    config => {
        if (config.url != "/login") {
            let token = localStorage.getItem("token");
            token && (config.headers.Authorization = token);
        }
        return config

    },
    //请求失败回调
    (err) => {
        return Promise.reject(err)
    }
)

// 响应拦截
http.interceptors.response.use(
    // 响应成功回调函数
    (result) => {
        return Promise.resolve(result)
    },
    //响应失败回调
    (err) => {
        return Promise.reject(err)
    }
)
// 导出 http
export default http
